﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GFE.SharePoint.Attributes;
using GFE.SharePoint.Interfaces;

namespace GFE.SharePoint.Lazy
{
    public static class GFEMVPLazyExtensions
    {
        public static GFEMVPLazy<T> AsGFEMVPLazy<T>(this GFELazy<T> lazy) where T : IGFEMVPSupervisor
        {
            var AscxPath = default(string);
            var gfeMvpClassAttribute = lazy.Value.GetType().GetMEFAttribute<GFEMVPClassAttribute>();
            if (gfeMvpClassAttribute == default(GFEMVPClassAttribute)) return default(GFEMVPLazy<T>);

            var presenterClass = gfeMvpClassAttribute.Presenter;
            var viewClass = gfeMvpClassAttribute.View;
            var gfeMVPAscxPathAttribute = lazy.Value.GetType().GetMEFAttribute<GFEMVPAscxPathAttribute>();
            AscxPath = gfeMVPAscxPathAttribute == default(GFEMVPAscxPathAttribute) ? "" : gfeMVPAscxPathAttribute.AscxPath;

            return new GFEMVPLazy<T>(lazy, gfeMvpClassAttribute.View, gfeMvpClassAttribute.Presenter, AscxPath);
        }
    }
}
